//
//  BaseViewController.swift
//  WeiBo
//
//  Created by Tony on 2017/12/27.
//  Copyright © 2017年 Tony. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    // MARK:-懒加载
    lazy var visitorView:  VisitorView = VisitorView.visitorView()
    
    // MARK:-定义变量
    var isLogin:  Bool = UserAccoutViewModel.shareInstance.isLogin
    
    // MARK:-系统回调
    override func loadView() {
        
        isLogin ?super.loadView() :setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNavItem()
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewController.registerBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }

}

// MARK:-初始化UI
private extension BaseViewController {
    
    func setupVisitorView() {
        self.view = visitorView
    }
    
    func setupNavItem() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style:.plain, target: self, action: #selector(BaseViewController.loginBtnClick))
    }
}
// MARK:-事件监听
extension BaseViewController {
    @objc func registerBtnClick() {
        mySelfLog()

    }
    @objc func loginBtnClick() {        
        // init
        let oauthVc = OAuthiewController()
        
        // 包装成导航控制器
        let nav = UINavigationController.init(rootViewController: oauthVc)
        
        // Modal
        present(nav, animated: true, completion: nil)
    }
}
